package com.spzx.cart.api.fallback;

import com.spzx.cart.api.CartFeignClient;
import com.spzx.cart.api.domain.CartInfo;
import com.spzx.common.core.domain.R;
import lombok.extern.slf4j.Slf4j;
import org.springframework.cloud.openfeign.FallbackFactory;

import java.util.List;

/**
 * @ClassName CartFeignClientFallbackFactory
 * @Author 波
 * @Date 2024/8/11 14:07
 */
@Slf4j
public class CartFeignClientFallbackFactory implements FallbackFactory<CartFeignClient> {
    @Override
    public CartFeignClient create(Throwable cause) {
        return new CartFeignClient() {
            @Override
            public R<List<CartInfo>> getCartCheckedList(Long userId, String source) {
                log.error("获取购物车选中商品失败" + cause.getMessage());
                return R.fail(cause.getMessage());
            }

            @Override
            public R<Boolean> updateCartCheckedPrice(Long userId, String source) {
                log.error("更新购物车价格失败" + cause.getMessage());
                return R.fail("更新购物车价格失败" + cause.getMessage());
            }

            @Override
            public R<Boolean> deleteCheckedCartInfo(Long userId, String source) {
                log.error("清空购物车选中购物项失败" + cause.getMessage());
                return R.fail("清空购物车选中购物项失败" + cause.getMessage());
            }
        };
    }
}
